/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package th.stripes.action;

import able.stripes.JSP;
import com.google.inject.Inject;

import com.oas.thit._this.cardstmt.xsd.CardStatementRequestBody;
import com.oas.thit._this.cardstmt.xsd.CardStatementResponseBody;
import com.oas.thit._this.cardstmt.xsd.CardStatementResponseLineItem;

import com.oas.thit._this.pin.xsd.AccountValidationResponseBody;
import com.oas.thit._this.profile.depositor.update.xsd.DepositorProfileUpdateRequestBody;
import com.oas.thit._this.profile.depositor.xsd.DepositorProfileResponseBody;
import com.oas.thit._this.pin.xsd.CustodianValidationRequestBody;
import com.oas.thit._this.pin.xsd.CustodianValidationResponseBody;
import com.oas.thit._this.stmt.xsd.StatementRequestBody;
import com.oas.thit._this.stmt.xsd.StatementResponseBody;
import com.oas.thit._this.stmt.xsd.StatementResponseLineItem;
import com.oas.thit._this.xsd.THISBaseDataElementBody;
import com.oas.thit.xmlmessage.xsd.Header;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.bind.JAXBElement;
import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sourceforge.stripes.action.Before;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.DontValidate;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.action.UrlBinding;
import net.sourceforge.stripes.controller.LifecycleStage;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import th.config.ableContextListener;
import th.dao.KodAkaunDAO;
import th.dao.KodJantinaDAO;
import th.dao.KodKahwinDAO;
import th.dao.KodNegeriDAO;
import th.dao.KodPekerjaanDAO;
import th.dao.KodSektorPekerjaanDAO;
import th.dao.KodStatusDAO;
import th.dao.KodUrusanDAO;
import th.dao.KodWarganegaraDAO;
import th.dao.PoskodDAO;
import th.manager.AkaunFavManager;
import th.manager.AkaunManager;
import th.manager.DepositManager;
import th.manager.ResponseManager;
import th.manager.SMSgatewayManager;
import th.manager.SejarahTransaksiManager;
import th.model.Akaun;
import th.model.AkaunFav;
import th.model.Deposit;
import th.model.InfoAudit;
import th.model.KodAkaun;
import th.model.KodKebenaranTransaksi;
import th.model.Pengguna;
import th.model.PenyataAkaun;
import th.model.PenyataKad;
import th.model.PindahanSimpanan;
import th.model.Poskod;
import th.model.SejarahTransaksi;
import th.stripes.BaseActionBean;
import th.stripes.Configuration;
import th.stripes.WelcomeActionBean;
import th.stripes.config.AuthRequired;
import th.stripes.services.DepositService;
import th.stripes.util.AccCheckUtil;
import th.stripes.util.ReportUtil;
import th.stripes.webservice.WebServiceUtil;


/**
 *
 * @author ubuntu
 */
@AuthRequired
@UrlBinding("/deposit")
public class DepositActionBean extends BaseActionBean{    
    
    //update 11092014
    private AkaunFav akaunFav;
    @Inject AkaunFavManager akaunFavManager;
    private List<AkaunFav> accFavList;
    
    private Deposit deposit;
    private Pengguna pengguna;
    private ArrayList penyataAkaunList; 
    private List<Akaun> accountList;
    private Akaun akaun;
    @Inject
    private WebServiceUtil webUtil;    
    @Inject 
    private DepositManager depositManager;
    @Inject 
    private AkaunManager akaunManager;
    @Inject 
    private KodNegeriDAO kodNegeriDAO;
    @Inject
    private KodJantinaDAO kodJantinaDAO;
    @Inject
    private KodKahwinDAO kodKahwinDAO;
    @Inject
    private PoskodDAO poskodDAO;
    @Inject
    private KodPekerjaanDAO kodPekerjaanDAO;
    @Inject
    private KodSektorPekerjaanDAO kodSektorPekerjaanDAO;
    @Inject
    private KodWarganegaraDAO kodWarganegaraDAO;
    @Inject
    private ResponseManager responseManager;
    @Inject
    SMSgatewayManager sMSgatewayManager;
    @Inject 
    private ReportUtil reportUtil;
    @Inject 
    private KodUrusanDAO kodUrusanDAO;
    @Inject 
    private KodStatusDAO kodStatusDAO;
    @Inject
    private KodAkaunDAO kodAkaunDAO;
    @Inject
    private SejarahTransaksiManager sejarahTransaksiManager;
    @Inject
    Configuration conf;
    
    @Inject
    private DepositService resource;
    
    
    private static String SUCCESSFUL = "0000";
    private static String SYSTEM_ERROR = "9999";   
    private static String INVALID_ACC_IC = "9000";    
    private static String BAL_ENQ_MSG_ID = "TPBALENQWD01";
    private static String STAT_ENQ_MSG_ID = "TPTHSTMTWD01";
    private static String PROFILE_ENQ_MSG_ID = "TPDPPROFWD01";
    private static String UPD_PROFILE_MSG_ID = "TPDPPROFWD02";
    private static String ADD_ACC_MSG_ID = "TPUSRMGTWD02";
    private static String HEADER_ID_BALANCE_ENQUIRY = "THSBENQ";
    private static String HEADER_ID_STATEMENT_ENQUIRY = "THSSTMT";
    private static String HEADER_ID_PROFILE_ENQUIRY = "THSDPQR";
    private static String HEADER_ID_UPD_PROFILE = "THSDPUP";    
    private static String HEADER_ID_ADD_ACCOUNT = "THSCUVL";
    private static String VAL_ACC_MSG_ID = "TPUSRMGTWD03";
    private static String HEADER_ID_VAL_ACCOUNT = "THSACVL";
    //private static String STAT_CARD_ENQ_MSG_ID = "TPCTMTMWD01"; //-20/6/2014
    private static String STAT_CARD_ENQ_MSG_ID = "TPTHCTMTWD01"; //-02/7/2014
    private static String HEADER_ID_CARD_STATEMENT_ENQUIRY = "THSCTMT";//-26/6/2014
    
    private static String IPDKWSP_ACCOUNT = "11";
    private static String CUSTODIAN_ACCOUNT = "02";
    
    private static String HEADER_ID_VAL_FAV_ACCOUNT = "THSACVL";
    private static String VAL_FAV_ACC_MSG_ID = "TPUSRMGTWD04"; //add 25/10/2014
    private static String ACC_STS_EPF = "9206";
    private static String ADD_FAV_ACC = "ADDFAV"; // ADD 18/09/2014
    private static String HEADER_ID_ADD_FAV_ACC = "THFAVADD"; // ADD 18/09/2014
    private static String HEADER_ID_EDIT_FAV_ACC = "THFAVEDIT"; // ADD 26/09/2014
    private static String EDIT_FAV_ACC = "EDITFAV"; // ADD 18/09/2014
    
    private static Logger LOG = LoggerFactory.getLogger(DepositActionBean.class);
    
    // Call Web Service Operation
    private com.oas.thit._this.services.THISServices service = new com.oas.thit._this.services.THISServices();
    private com.oas.thit._this.services.THISServicesPortType port = service.getTHISServicesHttpSoap11Endpoint();
    
    @DefaultHandler
    public Resolution showMainForm() {
        return new JSP("deposit/main_page.jsp");
    }
    
    @Before(stages={LifecycleStage.BindingAndValidation})
    public void rehydrate() {
        pengguna = getContext().getCurrentUser();
        if (pengguna != null) {
            accountList = pengguna.getSenaraiAkaun();
            accFavList = pengguna.getSenaraiAkaunFav(); //update 11092014
        }
    }
        
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-SEMAK BAKI AKAUN-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+// 
    public Resolution showFormBalanceInquiry() { 
        if(deposit == null)
            deposit = new Deposit();
        deposit.setNoKp(pengguna.getNoKp());
        deposit.setNoAkaun(akaunManager.getNoAkaun(deposit.getNoKp(), "Y"));
        return new JSP("deposit/pertanyaan_baki_akaun.jsp");
    }  
    
    public Resolution checkBalance(){        
        
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        
        boolean check = checking.checkAcc(deposit, pengguna);
        
        if (!check) {
            addSimpleError("" + responseManager.getResponseMessage("9000", BAL_ENQ_MSG_ID));
            return new JSP("deposit/msg.jsp");
        }
        
//        DecimalFormat formatter = new DecimalFormat("#,#######.##");
        Format formatter = new DecimalFormat("#,#######.##");
        String responseCode = "";
        
        try { // Call Web Service Operation
            
            
            responseCode =
                    resource.inquiryBalance(deposit, pengguna, responseCode,
                            getContext().getRequest().getSession().getId());
            
            if (SUCCESSFUL.equals(responseCode)) {
                return new JSP("deposit/pertanyaan_baki_detail.jsp");
            }
            
        } catch (Exception ex) {
        // TODO handle custom exceptions here
            LOG.error("error {}", ex);
            responseCode = SYSTEM_ERROR;
        } 
//        sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi); 
        addSimpleError("" + responseManager.getResponseMessage(responseCode, BAL_ENQ_MSG_ID));
        return new JSP("deposit/msg.jsp");
    }

    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-KEMASKINI AKAUN PENGGUNA-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+// 
    public Resolution showDetailForm() {        
        return new JSP("deposit/add_accounts_detail.jsp");
    }
    
    public Resolution showAddAccForm(){
        return new JSP("deposit/add_accounts.jsp");
    }
    
    public Resolution addAcc() {
        String noAkaunPenjaga = "";
        String noKpPenjaga = "";
        pengguna = getContext().getCurrentUser();       
        
        if (validateAkaun(akaun.getAkaunTmbhn(), pengguna.getNoKp())){
            addSimpleError("Akaun telah wujud!");
            return new JSP("deposit/add_accounts_detail.jsp");
        }
        
        String checkingResult = webUtil.checkAkaunWithKp(akaun.getAkaunTmbhn(), akaun.getNoPengenalanTmbhn());
        if (!"0000".equals(checkingResult)) {
            addSimpleError("" + responseManager.getResponseMessage(checkingResult, BAL_ENQ_MSG_ID));
            return new JSP("deposit/add_accounts_detail.jsp");
        }
        
        String responseCode = "";
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi(); 
        if(deposit.getJenisAkaun().equals(IPDKWSP_ACCOUNT)){
            
            try { 
                // Call Web Service Operation
                // TODO initialize WS operation arguments here
                com.oas.thit._this.xsd.THISRequest req = new com.oas.thit._this.xsd.THISRequest();
                // TODO process result here                
                com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();
                req.setHeader(webUtil.createHeader(VAL_ACC_MSG_ID, HEADER_ID_VAL_ACCOUNT));
                THISBaseDataElementBody reqBody = objFactory.createTHISBaseDataElementBody();
                
                reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(akaun.getAkaunTmbhn()));
                reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(pengguna.getNoKp()));
                
                JAXBElement<THISBaseDataElementBody> jReqBody =  objFactory.createTHISRequestBody(reqBody);
                req.setBody(jReqBody);
                
                com.oas.thit._this.pin.xsd.AccountValidationResponse result = port.validateAccount(req);
                
                Header header = result.getHeader().getValue();
                responseCode = header.getResponseCode().getValue();
                    //acct sts active,bankrupt,dormant,sulit
                    if (responseCode.equals(SUCCESSFUL) || responseCode.equals(ACC_STS_EPF)) {
                        AccountValidationResponseBody resp = result.getBody().getValue(); 
                        if(resp.getTHAcctType()!=null && (resp.getTHAcctType().getValue().trim().equals(IPDKWSP_ACCOUNT))){
                            Akaun kwsp = new Akaun();
                            InfoAudit ia = new InfoAudit();
                            ia.setDimasukOleh(pengguna);
                            ia.setTarikhMasuk(new Date());
                            kwsp.setPengguna(pengguna);
                            kwsp.setAkaunTmbhn(akaun.getAkaunTmbhn());
                            kwsp.setNoPengenalanTmbhn(pengguna.getNoKp());
                            kwsp.setNamaAkaunTmbhn(resp.getTHName().getValue().trim()); 
                            kwsp.setAkaunUtama("N");
                            kwsp.setInfoAudit(ia);
                            KodAkaun jenisAkaun = kodAkaunDAO.findById(IPDKWSP_ACCOUNT);
                            if (jenisAkaun != null)
                                kwsp.setJenisAkaun(jenisAkaun);
                            depositManager.saveAccount(kwsp);                 
                            addSimpleMessage(responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID));
                            return new JSP("deposit/add_accounts.jsp");  
                        }
                    }
                
                } catch (Exception ex) {
                    LOG.error("error {}", ex);
                    responseCode = SYSTEM_ERROR;
                    addSimpleError("" + responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID)); 
                }
            
        }else if(deposit.getJenisAkaun().equals(CUSTODIAN_ACCOUNT)){
            if (pengguna != null) {
                noAkaunPenjaga = akaunManager.getNoAkaun(pengguna.getNoKp(), "Y");
                noKpPenjaga = pengguna.getNoKp();
            }
            try {
                com.oas.thit._this.pin.xsd.CustodianValidationRequest req = new com.oas.thit._this.pin.xsd.CustodianValidationRequest();
                com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();
                com.oas.thit._this.pin.xsd.ObjectFactory pinObjFactory = new com.oas.thit._this.pin.xsd.ObjectFactory();
                req.setHeader( webUtil.createHeader(ADD_ACC_MSG_ID, HEADER_ID_ADD_ACCOUNT));

                CustodianValidationRequestBody reqBody = pinObjFactory.createCustodianValidationRequestBody();
                reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(akaun.getAkaunTmbhn()));
                reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(akaun.getNoPengenalanTmbhn()));
                reqBody.setParentAcct(pinObjFactory.createCustodianValidationRequestBodyParentAcct(noAkaunPenjaga));
                reqBody.setParentICNo(pinObjFactory.createCustodianValidationRequestBodyParentICNo(noKpPenjaga));

                JAXBElement<CustodianValidationRequestBody> jReqBody =  pinObjFactory.createCustodianValidationRequestBody(reqBody);
                req.setBody(jReqBody);
                // TODO process result here
                com.oas.thit._this.pin.xsd.CustodianValidationResponse result = port.custodianValidation(req);
                Header header = result.getHeader().getValue();
                responseCode = header.getResponseCode().getValue();
                sejarahTransaksi.setPengguna(pengguna);
                sejarahTransaksi.setTrhMasuk(new Date());
                sejarahTransaksi.setUrusan(kodUrusanDAO.findById(ADD_ACC_MSG_ID));
                sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
                sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
                sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());
                sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi); 
                if (responseCode.equals(SUCCESSFUL)) {
                    CustodianValidationResponseBody resp = result.getBody().getValue();                
                    InfoAudit ia = new InfoAudit();
                    ia.setDimasukOleh(pengguna);
                    ia.setTarikhMasuk(new Date());
                    akaun.setNoPengenalanTmbhn(akaun.getNoPengenalanTmbhn());
                    akaun.setNamaAkaunTmbhn(resp.getTHName().getValue().trim());
                    akaun.setPengguna(pengguna);
                    akaun.setInfoAudit(ia);
                    KodAkaun jenisAkaun = kodAkaunDAO.findById(CUSTODIAN_ACCOUNT);
                            if (jenisAkaun != null)
                                akaun.setJenisAkaun(jenisAkaun);
                    depositManager.saveAccount(akaun);                 
                    addSimpleMessage(responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID));
                    return new JSP("deposit/add_accounts.jsp");
                }             
            } catch (Exception ex) {
                LOG.error("error {}", ex);
                responseCode = SYSTEM_ERROR;
            }
        }
        addSimpleError("" + responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID));  
        return new JSP("deposit/msg.jsp");
    }
    
    private boolean validateAkaun(String noAkaun, String noKPPenjaga) {
        return depositManager.childAccAuthenticate(noAkaun, noKPPenjaga);        
    }
    
    public Resolution deleteAkaun() {
        String noAkaun = getContext().getRequest().getParameter("noAkaun");
        if (StringUtils.isNotBlank(noAkaun)) {
            akaunManager.deleteAkaun(noAkaun);
        }
        return showAddAccForm();
    }
    
    public Resolution getNoKP() {
        String noAkaun = getContext().getRequest().getParameter("noAkaun");
        String noPengenalan = "";
        if (StringUtils.isNotBlank(noAkaun)){
             noPengenalan = akaunManager.getNoPengenalan(noAkaun);
        }
        return new StreamingResolution( "text/plain",noPengenalan );
    }    
    
    
     public Resolution showEditForm() {        
         String noAkaun = getContext().getRequest().getParameter("noAkaun");
         if (StringUtils.isNotBlank(noAkaun)) {
             akaun = akaunManager.getAkaun(noAkaun);
         }
        return new JSP("deposit/add_accounts_detail.jsp");
    }
    
      //-+-+-+-+-+-+-+-+-+-+-+-+-+-KEMASKINI AKAUN FAVOURITE-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
    

    public Resolution showFavAcc(){
        
         if(deposit==null)
            deposit = new Deposit();
   
        return new JSP("deposit/show_fav_acc.jsp");  
    }
     
    public Resolution addFavAccForm(){
        return new JSP("deposit/add_fav_acc_form.jsp");
    }

    
    
    public Resolution showAddFavDetail (){
    
        //AkaunFav akaunFav = (AkaunFav)getContext().getRequest().getSession().getAttribute("akaunFav");
        //akaunFav = new AkaunFav();
        String responseCode = "";
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
        InfoAudit ia = new InfoAudit();
        
        deposit.setNoAkaunFav(deposit.getNoAkaunFav());
        deposit.setNicknameAkaunFav(deposit.getNicknameAkaunFav());
        //deposit.setNamaAkaunFav(deposit.getNamaAkaunFav());
        
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);

        boolean check = checking.checkAddAccFav(deposit, pengguna); 
        
        if (check) {
            addSimpleError("AKAUN SUDAH DIDAFTAR");
            return new JSP("deposit/msg.jsp");
        }
      
        try { 
              // Call Web Service Operation
              // TODO initialize WS operation arguments here
              com.oas.thit._this.xsd.THISRequest req = new com.oas.thit._this.xsd.THISRequest();
              // TODO process result here                
              com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();
              req.setHeader(webUtil.createHeader(VAL_FAV_ACC_MSG_ID, HEADER_ID_VAL_FAV_ACCOUNT));
              THISBaseDataElementBody reqBody = objFactory.createTHISBaseDataElementBody();

              reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(deposit.getNoAkaunFav()));
             // reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(deposit.getNoKpFav()));

              JAXBElement<THISBaseDataElementBody> jReqBody =  objFactory.createTHISRequestBody(reqBody);
              req.setBody(jReqBody);

              com.oas.thit._this.pin.xsd.AccountValidationResponse result = port.validateAccount(req);

              Header header = result.getHeader().getValue();
              responseCode = header.getResponseCode().getValue();

              sejarahTransaksi.setPengguna(pengguna);
              sejarahTransaksi.setTrhMasuk(new Date());
              sejarahTransaksi.setUrusan(kodUrusanDAO.findById(ADD_FAV_ACC));
              sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
              sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
              sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());
              sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi); 

              if (responseCode.equals(SUCCESSFUL)) {
                  AccountValidationResponseBody resp = result.getBody().getValue(); 

                  AkaunFav akaunFav = new AkaunFav();
//                          InfoAudit ia = new InfoAudit();
//                          ia.setDimasukOleh(pengguna);
//                          ia.setTarikhMasuk(new Date());
                  if (deposit.getNoAkaunFav().equals(resp.getTHAcct().getValue().trim())) {
                      akaunFav.setNoAkaunFav(resp.getTHAcct().getValue().trim());
                  }
                  //testing
                  String a = resp.getTHName().getValue().trim();
                  String b = resp.getTHAcctStatus().getValue().trim();
                  String c = resp.getTHAcctType().getValue().trim();
                  String d = resp.getTHPassbookNo().getValue().trim();
                  
                  System.out.println("------------Testing-------------");
                  System.out.println("Nama Fav Core : " + a);
                  System.out.println("Acc Status Fav Core : " + b);
                  System.out.println("Acc type Fav Core : " + c);
                  System.out.println("Passbook Fav Core : " + d);
                  System.out.println("-------------------------");
                  
                  akaunFav.setNamaAkaunFav(resp.getTHName().getValue().trim());
                  akaunFav.setInfoAudit(ia);
                  akaunFav.setPenggunaFav(pengguna);
                  KodAkaun jenisAkaun = kodAkaunDAO.findById(resp.getTHAcctType().getValue());
                  if (jenisAkaun != null)
                      akaunFav.setJenisAkaun(jenisAkaun);                

                  //set dlm deposit
                  deposit.setNoAkaunFav(resp.getTHAcct().getValue().trim());
                  deposit.setNicknameAkaunFav(deposit.getNicknameAkaunFav());
                  deposit.setFavStatusAcc(resp.getTHAcctStatus().getValue().trim());
                  deposit.setFavTypeAcc(resp.getTHAcctType().getValue().trim());
                  deposit.setFavPassbook(resp.getTHPassbookNo().getValue().trim());
                  deposit.setNamaAkaunFav(resp.getTHName().getValue().trim());
                 // akaunFavManager.saveAccountFav(akaunFav); 

                  //addSimpleMessage(responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID));
//                          return new JSP("deposit/show_fav_acc.jsp");  
              }else{ 
                addSimpleError("" + responseManager.getResponseMessage(responseCode, VAL_FAV_ACC_MSG_ID)); 
                return new JSP("deposit/add_fav_acc_form.jsp");
            }

          } catch (Exception ex) {
              LOG.error("error {}", ex);
              responseCode = SYSTEM_ERROR;
              addSimpleError("" + responseManager.getResponseMessage(responseCode, VAL_FAV_ACC_MSG_ID)); 
          }
        
        getContext().getRequest().getSession().setAttribute("deposit", deposit); 
      
        return new JSP("deposit/add_fav_acc_TAC.jsp");
    }
    
    public Resolution showEditFavDetail() {
    
        deposit.setNoAkaunFav(deposit.getNoAkaunFav());
        deposit.setNicknameAkaunFav(deposit.getNicknameAkaunFav());
        //deposit.setNamaAkaunFav(deposit.getNamaAkaunFav());
      
        getContext().getRequest().getSession().setAttribute("deposit", deposit); 
        
        return new JSP("deposit/edit_fav_acc_TAC.jsp");
    }
    /*
     * Save New Fav Acc
     */
    public Resolution saveFavAcc() {
        
        pengguna = getContext().getCurrentUser();
        String responseCode = "";
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
        HttpSession ses = context.getRequest().getSession();
      
        InfoAudit ia = new InfoAudit();
        ia.setDimasukOleh(pengguna);
        ia.setTarikhMasuk(new Date());
        
        
        KodKebenaranTransaksi kodKebenaranTransaksi = sMSgatewayManager.findKodKebenaranTransaksiBySessionId(ses.getId(), HEADER_ID_ADD_FAV_ACC, "Y");
        if(kodKebenaranTransaksi != null){            
            if(kodKebenaranTransaksi.getSah().equals("Y") && kodKebenaranTransaksi.getKodKebenaranTransaksi().equals(deposit.getTacNumber())){
                kodKebenaranTransaksi.setInfoAudit(ia);
                kodKebenaranTransaksi.setSah("N");                 
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
      
//                deposit.setNoAkaunFav(deposit.getNoAkaunFav());
//                deposit.setNicknameAkaunFav(deposit.getNicknameAkaunFav());
//                deposit.setNamaAkaunFav(deposit.getNamaAkaunFav());
                AkaunFav akaunFav = new AkaunFav();
                akaunFav.setNoAkaunFav(deposit.getNoAkaunFav());
                akaunFav.setNamaAkaunFav(deposit.getNamaAkaunFav());
                akaunFav.setNicknameFav(deposit.getNicknameAkaunFav());
                akaunFav.setInfoAudit(ia);
                akaunFav.setPenggunaFav(pengguna);
//                KodAkaun jenisAkaun = kodAkaunDAO.findById(resp.getTHAcctType().getValue());
//                if (jenisAkaun != null)
//                      akaunFav.setJenisAkaun(jenisAkaun);                

                akaunFavManager.saveAccountFav(akaunFav); 

                addSimpleMessage("FAVOURITE ACCOUNT BERJAYA DITAMBAH"); 
                
        }else{ 
                addSimpleError("KOD PENGESAHAN TRANSAKSI(TAC) TIDAK SAH");
                return new JSP("deposit/add_fav_acc_TAC.jsp");
            }
        }else{
            addSimpleError("KOD PENGESAHAN TRANSAKSI(TAC) TIDAK SAH");
            return new JSP("deposit/add_fav_acc_TAC.jsp");
        }
        sMSgatewayManager.saveTAC(kodKebenaranTransaksi);
        return new JSP("deposit/msg.jsp");   
        //return new JSP("deposit/msg.jsp");   
//        addSimpleError("" + responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID));
//        return new JSP("deposit/show_fav_acc.jsp"); 
         
    }
   
    /*
     * Save edit/update Fav acc
     */        
    public Resolution updateFavAcc() {
        
        pengguna = getContext().getCurrentUser();
        String responseCode = "";
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
        HttpSession ses = context.getRequest().getSession();
      
        InfoAudit ia = new InfoAudit();
        ia.setDimasukOleh(pengguna);
        ia.setTarikhMasuk(new Date());
        
        
        KodKebenaranTransaksi kodKebenaranTransaksi = sMSgatewayManager.findKodKebenaranTransaksiBySessionId(ses.getId(), HEADER_ID_EDIT_FAV_ACC, "Y");
        if(kodKebenaranTransaksi != null){            
            if(kodKebenaranTransaksi.getSah().equals("Y") && kodKebenaranTransaksi.getKodKebenaranTransaksi().equals(deposit.getTacNumber())){
                kodKebenaranTransaksi.setInfoAudit(ia);
                kodKebenaranTransaksi.setSah("N");                 
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
      
                /* TODO : need new webservice
                 * 
                 */
            AkaunFav akaunFav = new AkaunFav();

            akaunFav.setNoAkaunFav(deposit.getNoAkaunFav());
            akaunFav.setNicknameFav(deposit.getNicknameAkaunFav());
            akaunFavManager.updateAccFavByNoAcc(akaunFav);
            
            //return new JSP("deposit/show_fav_acc.jsp");
           // addSimpleMessage(responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID));
            addSimpleMessage("KEMASKINI FAVOURITE ACCOUNT BERJAYA");
            return new JSP("deposit/show_fav_acc.jsp");  
            }
        }else{ 
            addSimpleError("KOD PENGESAHAN TRANSAKSI(TAC) TIDAK SAH");
            return new JSP("deposit/edit_fav_acc_TAC.jsp");
        }
        sMSgatewayManager.saveTAC(kodKebenaranTransaksi);
        return new JSP("deposit/msg.jsp");   
        //return new JSP("deposit/msg.jsp");   
//        addSimpleError("" + responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID));
//        return new JSP("deposit/show_fav_acc.jsp"); 
         
    }
    
    
    public Resolution editFavAccForm() {
        if (deposit == null) {
        deposit = new Deposit();
        }
        
        String noAkaunFav = getContext().getRequest().getParameter("noAkaunFav");
        if (StringUtils.isNotBlank(noAkaunFav)) {
            akaunFav = akaunFavManager.getAkaunFavByNoAcc(noAkaunFav);
            if (akaunFav != null){
                deposit.setNoAkaunFav(akaunFav.getNoAkaunFav().trim());
                //deposit.setNamaAkaunFav(akaunFav.getNamaAkaunFav().trim());
                deposit.setNicknameAkaunFav(akaunFav.getNicknameFav());
            }
            
        }
        getContext().getRequest().getSession().setAttribute("deposit", deposit);  
        return new JSP("deposit/edit_fav_acc_form.jsp");
    }
    
    
//    public Resolution editFavAccDetail() {
//        if(deposit==null)
//            deposit = new Deposit();
//        pengguna = getContext().getCurrentUser();
//        String responseCode = "";
//        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
//        HttpSession ses = context.getRequest().getSession();
//      
//        InfoAudit ia = new InfoAudit();
//        ia.setDimasukOleh(pengguna);
//        ia.setTarikhMasuk(new Date());
//        
//        String noAkaunFav = getContext().getRequest().getParameter("noAkaunFav");
//        if (StringUtils.isNotBlank(noAkaunFav)) {
//            akaunFavManager.editAccFavByNoAcc(noAkaunFav);
//            
//            sejarahTransaksi.setPengguna(pengguna);
//            sejarahTransaksi.setTrhMasuk(new Date());
//            sejarahTransaksi.setUrusan(kodUrusanDAO.findById(EDIT_FAV_ACC));
//            sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
//            //sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
//            //sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());
//            sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi); 
//        }
//        
//        //return new JSP("deposit/update_user_profile.jsp");
//        return new JSP("deposit/show_fav_acc.jsp");  
//    } 
    
    
    public Resolution deleteAkaunFav() {
        String noAkaun = getContext().getRequest().getParameter("noAkaunFav");
        if (StringUtils.isNotBlank(noAkaun)) {
            akaunFavManager.deleteAkaun(noAkaun);
        }
        return showFavAcc();
    }
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-KEMASKINI PROFIL PENGGUNA-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
    public Resolution showFormUpdateProfile() {
        if(deposit==null)
            deposit = new Deposit();
        return new JSP("deposit/update_user_profile.jsp");
    }    
    
    public Resolution showProfile() {
        
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        deposit.setNoKpDari(deposit.getNoKp());
        deposit.setNoAkaunDari(deposit.getNoAkaun());
        boolean check = checking.checkAcc(deposit, pengguna);
        
        if (!check) {
            addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
            return new JSP("deposit/msg.jsp");
        }
        
        //todo web service    
        String responseCode = "";
        DateFormat format = new SimpleDateFormat("yyyyMMdd");        
        try { // Call Web Service Operation
            com.oas.thit._this.services.THISServices service = new com.oas.thit._this.services.THISServices();
            com.oas.thit._this.services.THISServicesPortType port = service.getTHISServicesHttpSoap11Endpoint();
            // TODO initialize WS operation arguments here
            com.oas.thit._this.xsd.THISRequest req = new com.oas.thit._this.xsd.THISRequest();
            com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();
            
            req.setHeader( webUtil.createHeader(PROFILE_ENQ_MSG_ID, HEADER_ID_PROFILE_ENQUIRY) );
            
            THISBaseDataElementBody reqBody = objFactory.createTHISBaseDataElementBody();
            reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(deposit.getNoAkaun()));
            reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(deposit.getNoKp()));
            
            JAXBElement<THISBaseDataElementBody> jReqBody =  objFactory.createTHISRequestBody(reqBody);
            req.setBody(jReqBody);
            
            // TODO process result here
            com.oas.thit._this.profile.depositor.xsd.DepositorProfileResponse result = port.depositorProfileQuery(req);
            Header header = result.getHeader().getValue();
            responseCode = header.getResponseCode().getValue();
            if (responseCode.equals(SUCCESSFUL)) {
                DepositorProfileResponseBody resp = result.getBody().getValue();
                if ( resp != null ) {
                    deposit.setNoAkaun( resp.getTHAcct().getValue().trim() );
                    deposit.setNoKp( resp.getTHICNo().getValue().trim() );
                    deposit.setNama( resp.getTHName().getValue().trim() );
                    deposit.setJantina( kodJantinaDAO.findById( resp.getTHGender().getValue().trim()));
                    if(resp.getTHDOB().getValue().trim().equals("00010101"))
                        deposit.setTarikhLahir(null);
                    else 
                        deposit.setTarikhLahir( format.parse(resp.getTHDOB().getValue()));
                    deposit.setKahwin( kodKahwinDAO.findById(resp.getTHMarital().getValue().trim()));
                    deposit.setAlamat1( resp.getTHAddress1().getValue().trim());
                    deposit.setAlamat2( resp.getTHAddress2().getValue().trim() );
                    deposit.setAlamat3( resp.getTHAddress3().getValue().trim() );
                    if(resp.getTHPoskod().getValue()!=null){
                        Poskod poskod = poskodDAO.findById(resp.getTHPoskod().getValue().trim());
                        deposit.setPoskod( poskod.getPoskod());
                        deposit.setAlamat4(poskod.getNama());//deskripsi poskod
                    }
                    deposit.setNegeri(kodNegeriDAO.findById(resp.getTHState().getValue().trim()));
                    deposit.setNoTel1( resp.getTHPhoneHome().getValue().trim() );
                    deposit.setNoTel2( resp.getTHPhoneOffice().getValue().trim() );
                    deposit.setNoTel3( resp.getTHPhoneMobile().getValue().trim() );
                    deposit.setEmail(resp.getTHemail().getValue().trim()); 
                    
                    deposit.setNamaDatuk( resp.getTHMother().getValue().trim() );
                    if(resp.getTHEthnic().getValue()!=null)
                        deposit.setBangsa(resp.getTHEthnic().getValue().trim());                    
                    deposit.setWarganegara(kodWarganegaraDAO.findById(resp.getTHNationality().getValue().trim()));
                    deposit.setSektorPekerjaan(kodSektorPekerjaanDAO.findById(resp.getTHEmploy().getValue().trim()));
                }
                return new JSP("deposit/update_user_profile_form.jsp");
            }
            
        } catch (Exception ex) {
            LOG.error("error {}", ex);
            responseCode = SYSTEM_ERROR;
        } 
        addSimpleError("" + responseManager.getResponseMessage(responseCode, PROFILE_ENQ_MSG_ID));
        return new JSP("deposit/msg.jsp");        
    }

    public Resolution previewEditProfile() {   
        
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        deposit.setNoKpDari(deposit.getNoKp());
        deposit.setNoAkaunDari(deposit.getNoAkaun());
        boolean check = checking.checkAcc(deposit, pengguna);
        
        if (!check) {
            addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
            return new JSP("deposit/msg.jsp");
        }
        
        deposit.setKahwin(kodKahwinDAO.findById(deposit.getKahwin().getKod()));
        deposit.setNegeri(kodNegeriDAO.findById(deposit.getNegeri().getCode()));
        if (deposit.getSektorPekerjaan() != null)
            deposit.setSektorPekerjaan(kodSektorPekerjaanDAO.findById(deposit.getSektorPekerjaan().getKod()));
        return new JSP("deposit/view_updated_profile.jsp");
    }
    
    public Resolution tacRequest() {   
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        deposit.setNoKpDari(deposit.getNoKp());
        deposit.setNoAkaunDari(deposit.getNoAkaun());
        boolean check = checking.checkAcc(deposit, pengguna);
        
        if (!check) {
            addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
            return new JSP("deposit/msg.jsp");
        }
        return new JSP("deposit/view_updated_profile_TACrequest.jsp");
    }
    
    public Resolution saveUpdateProfile() {       
        
        pengguna = getContext().getCurrentUser();
        if (pengguna == null) {
            return new RedirectResolution(WelcomeActionBean.class)
                    .addParameter("message", "Sila LOG MASUK terlebih dahulu untuk menggunakan perkhidmatan ini.");
        }
        
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);
        deposit.setNoKpDari(deposit.getNoKp());
        deposit.setNoAkaunDari(deposit.getNoAkaun());
        boolean check = checking.checkAcc(deposit, pengguna);
        
        if (!check) {
            addSimpleError("" + responseManager.getResponseMessage("9000", PROFILE_ENQ_MSG_ID));
            return new JSP("deposit/msg.jsp");
        }
        
        InfoAudit ia = new InfoAudit();
        ia.setDimasukOleh(pengguna);
        ia.setTarikhMasuk(new Date());
        
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi(); 
        HttpSession ses = context.getRequest().getSession();
        KodKebenaranTransaksi kodKebenaranTransaksi = sMSgatewayManager.findKodKebenaranTransaksiBySessionId(ses.getId(), HEADER_ID_UPD_PROFILE, "Y");
        if(kodKebenaranTransaksi != null){            
            if(kodKebenaranTransaksi.getSah().equals("Y") && kodKebenaranTransaksi.getKodKebenaranTransaksi().equals(deposit.getTacNumber())){
                kodKebenaranTransaksi.setInfoAudit(ia);
                kodKebenaranTransaksi.setSah("N");
                String responseCode = "";                  
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                try { 
                    // Call Web Service Operation                    
                    com.oas.thit._this.services.THISServices service = new com.oas.thit._this.services.THISServices();
                    com.oas.thit._this.services.THISServicesPortType port = service.getTHISServicesHttpSoap11Endpoint();
                    // TODO initialize WS operation arguments here
                    com.oas.thit._this.profile.depositor.update.xsd.DepositorProfileUpdateRequest req 
                            = new com.oas.thit._this.profile.depositor.update.xsd.DepositorProfileUpdateRequest();

                    req.setHeader( webUtil.createHeader(UPD_PROFILE_MSG_ID, HEADER_ID_UPD_PROFILE ) );
                    com.oas.thit._this.profile.depositor.update.xsd.ObjectFactory objFactory = new com.oas.thit._this.profile.depositor.update.xsd.ObjectFactory();  
                    com.oas.thit._this.xsd.ObjectFactory _objFactory = new com.oas.thit._this.xsd.ObjectFactory();  
                    DepositorProfileUpdateRequestBody reqBody = objFactory.createDepositorProfileUpdateRequestBody();
                    reqBody.setTHAcct( _objFactory.createTHISBaseDataElementBodyTHAcct(deposit.getNoAkaun()) );
                    reqBody.setTHICNo( _objFactory.createTHISBaseDataElementBodyTHICNo( deposit.getNoKp()) );
                    reqBody.setTHName( _objFactory.createTHISResponseBodyTHName( deposit.getNama() ));
                    if(deposit.getJantina()!=null)
                       reqBody.setTHGender( objFactory.createDepositorProfileUpdateRequestBodyTHGender( deposit.getJantina().getKod() ));
                    else
                        reqBody.setTHGender( objFactory.createDepositorProfileUpdateRequestBodyTHGender(""));
                    if(deposit.getTarikhLahir()!=null)
                        reqBody.setTHDOB( objFactory.createDepositorProfileUpdateRequestBodyTHDOB( sdf.format(deposit.getTarikhLahir())) );
                    if(deposit.getKahwin()!=null)
                        reqBody.setTHMarital( objFactory.createDepositorProfileUpdateRequestBodyTHMarital( deposit.getKahwin().getKod()));
                    else
                        reqBody.setTHMarital( objFactory.createDepositorProfileUpdateRequestBodyTHMarital(""));
                    reqBody.setTHAddress1( _objFactory.createTHProfileRequestBodyTHAddress1( deposit.getAlamat1()) );
                    reqBody.setTHAddress2( _objFactory.createTHProfileRequestBodyTHAddress2( deposit.getAlamat2()) );
                    reqBody.setTHAddress3( _objFactory.createTHProfileRequestBodyTHAddress3( deposit.getAlamat3()) );
                    reqBody.setTHPoskod( _objFactory.createTHProfileRequestBodyTHPoskod( deposit.getPoskod()) );
                    if(deposit.getNegeri()!=null)
                        reqBody.setTHState( _objFactory.createTHProfileRequestBodyTHState( deposit.getNegeri().getCode()) );
                    else
                        reqBody.setTHState( _objFactory.createTHProfileRequestBodyTHState(""));
                    reqBody.setTHPhoneHome( objFactory.createDepositorProfileUpdateRequestBodyTHPhoneHome( deposit.getNoTel1()) );
                    reqBody.setTHPhoneOffice( objFactory.createDepositorProfileUpdateRequestBodyTHPhoneOffice( deposit.getNoTel2()) );
                    reqBody.setTHPhoneMobile( objFactory.createDepositorProfileUpdateRequestBodyTHPhoneMobile( deposit.getNoTel3()) );
                    reqBody.setTHemail( objFactory.createDepositorProfileUpdateRequestBodyTHemail( deposit.getEmail() ));
                    reqBody.setTHMother( objFactory.createDepositorProfileUpdateRequestBodyTHMother( deposit.getNamaDatuk()) );                    
                    if(deposit.getSektorPekerjaan()!=null)
                        reqBody.setTHEmploy( objFactory.createDepositorProfileUpdateRequestBodyTHEmploy( deposit.getSektorPekerjaan().getKod()) );
                    else
                        reqBody.setTHEmploy( objFactory.createDepositorProfileUpdateRequestBodyTHEmploy(""));                    
                    if(deposit.getWarganegara()!=null)
                        reqBody.setTHNationality(objFactory.createDepositorProfileUpdateRequestBodyTHNationality(deposit.getWarganegara().getKod()));
                    else
                        reqBody.setTHNationality(objFactory.createDepositorProfileUpdateRequestBodyTHNationality(""));
                    reqBody.setTHEthnic(objFactory.createDepositorProfileUpdateRequestBodyTHEthnic(deposit.getBangsa()));
                    JAXBElement<DepositorProfileUpdateRequestBody> jReqBody = objFactory.createDepositorProfileUpdateRequestBody(reqBody);
                    req.setBody( jReqBody );
                    // TODO process result here
                    com.oas.thit._this.profile.depositor.xsd.DepositorProfileResponse result = port.depositorProfileUpdate(req);
                    Header header = result.getHeader().getValue();
                    responseCode = header.getResponseCode().getValue();
                    sejarahTransaksi.setPengguna(pengguna);
                    sejarahTransaksi.setTrhMasuk(new Date());
                    sejarahTransaksi.setUrusan(kodUrusanDAO.findById(UPD_PROFILE_MSG_ID));
                    sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
                    sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
                    sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());
                    if (responseCode.equals(SUCCESSFUL)) {
                        addSimpleMessage(responseManager.getResponseMessage(responseCode, UPD_PROFILE_MSG_ID));
                    } else {
                        addSimpleError(responseManager.getResponseMessage(responseCode, UPD_PROFILE_MSG_ID));                
                    }                                      
                } catch (Exception ex) {        
                    LOG.error("error {}", ex);
                    responseCode = SYSTEM_ERROR; 
                    addSimpleError("" + responseManager.getResponseMessage(responseCode, UPD_PROFILE_MSG_ID));
                }
                sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi); 
                
            }else{ 
                addSimpleError("KOD PENGESAHAN TRANSAKSI(TAC) TIDAK SAH");
                return new JSP("deposit/view_updated_profile_TACrequest.jsp");
            }
        }else{
            addSimpleError("KOD PENGESAHAN TRANSAKSI(TAC) TIDAK SAH");
            return new JSP("deposit/view_updated_profile_TACrequest.jsp");
        }
        sMSgatewayManager.saveTAC(kodKebenaranTransaksi);
        return new JSP("deposit/msg.jsp");   
    } 
    
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-PENYATA AKAUN-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+// 
    public Resolution showFormStatementOfAccount(){
        if(deposit==null)
            deposit = new Deposit();
        return new JSP("deposit/show_account_statement_main.jsp");
    }    
    
    public Resolution checkStatement() {      
        
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);        
        
        deposit.setNoAkaun(deposit.getNoAkaunDari());
        deposit.setNoKp(deposit.getNoKpDari());
        
        boolean check = checking.checkAcc(deposit, pengguna);
        
        if (!check) {
            addSimpleError("" + responseManager.getResponseMessage("9000", BAL_ENQ_MSG_ID));
            return new JSP("deposit/msg.jsp");
        }
        
        String noAkaunPenjaga = "";
        String noKpPenjaga = "";
        pengguna = getContext().getCurrentUser(); 

        //deposit.setNoKpDari(deposit.getNoKp());
        //deposit.setNoAkaunDari(deposit.getNoAkaun());
        //pengguna.getNoKp();
        
        if ((pengguna.getNoKp()).equals(deposit.getNoKpDari())) {
             deposit.setNoKpDari(deposit.getNoKp());
             deposit.setNoAkaunDari(deposit.getNoAkaun());
        } else {
            noAkaunPenjaga = akaunManager.getNoAkaun(pengguna.getNoKp(), "Y");
            noKpPenjaga = pengguna.getNoKp();
            
            deposit.setNoKpPenjaga(noKpPenjaga);
            deposit.setNoAkaunPenjaga(noAkaunPenjaga);
            deposit.setNoKpDari(deposit.getNoKp());
            deposit.setNoAkaunDari(deposit.getNoAkaun());
        }
         
        //add in 25092014
        deposit.setBulanPilihan(deposit.getBulanPilihan());
        
        
        
        // check status akaun
//        String getJnsAkaun = getJenisAkaun(deposit.getNoAkaunDari(), deposit.getNoKpDari());
//        if (getJnsAkaun!= null) {
//            if (getJnsAkaun.equals(CUSTODIAN_ACCOUNT)) {
//                 noAkaunPenjaga = akaunManager.getNoAkaun(pengguna.getNoKp(), "Y");
//                 noKpPenjaga = pengguna.getNoKp();
//            }
//        }
        
       
        
        DecimalFormat formatter = new DecimalFormat("#,###.##");
        SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");
        DateFormat dateformat = new SimpleDateFormat("yyyyMMdd");
        //DateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String responseCode = "";
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
        
        //by selected month, get start and end date
        //selected month = 032014 MMyyyy
         String selectedMonth = deposit.getBulanPilihan();
         String month = selectedMonth.substring(0, 2);
         String year = selectedMonth.substring(2, 6);
         
         //get start date
         String firstDate = dateformat.format(getFirstDayOfMonth(month, year));
         String lastDate = dateformat.format(getLastDayOfMonth(month, year));
         
        try { 
            // Call Web Service Operation
            
            com.oas.thit._this.stmt.xsd.StatementRequest req = new com.oas.thit._this.stmt.xsd.StatementRequest();
            com.oas.thit._this.stmt.xsd.ObjectFactory objFactoryStmt = new com.oas.thit._this.stmt.xsd.ObjectFactory();
            com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();
            
            req.setHeader(webUtil.createHeader(STAT_ENQ_MSG_ID, HEADER_ID_STATEMENT_ENQUIRY));
            com.oas.thit._this.stmt.xsd.StatementRequestBody reqBody = new com.oas.thit._this.stmt.xsd.StatementRequestBody();
            
            reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(deposit.getNoAkaunDari()));
            reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(deposit.getNoKpDari()));
            reqBody.setTHStmtStartDate(objFactoryStmt.createStatementRequestBodyTHStmtStartDate(firstDate));
            reqBody.setTHStmtEndDate(objFactoryStmt.createStatementRequestBodyTHStmtEndDate(lastDate));
              
            JAXBElement<StatementRequestBody> jReqBody =  objFactoryStmt.createStatementRequestBody(reqBody);

            req.setBody(jReqBody);
            
            // TODO process result here
            com.oas.thit._this.stmt.xsd.StatementResponse result = port.statementRequest(req);
            
            Header header = result.getHeader().getValue();
            responseCode = header.getResponseCode().getValue();
            sejarahTransaksi.setPengguna(pengguna);
            sejarahTransaksi.setTrhMasuk(new Date());
            sejarahTransaksi.setUrusan(kodUrusanDAO.findById(STAT_ENQ_MSG_ID));
            sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
            sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
            sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());                    
            if (responseCode.equals(SUCCESSFUL)) {                
                StatementResponseBody resp = result.getBody().getValue();
                deposit.setNama(resp.getTHName().getValue());
                deposit.setAlamat1(resp.getTHAddress1().getValue());
                deposit.setAlamat2(resp.getTHAddress2().getValue());
                deposit.setAlamat3(resp.getTHAddress3().getValue());
                deposit.setPoskod(resp.getTHPoskod().getValue());
          //      deposit.setTarikhTransaksi(dateformat.parse(resp.getTHStmtDate().getValue()));
                deposit.setNoAkaun( resp.getTHAcct().getValue() ); 
                deposit.setNoKp(resp.getTHICNo().getValue());
                deposit.setNegeriDesc(resp.getTHState().getValue().trim());
                List<StatementResponseLineItem> items  = resp.getLineItems();
                int itemsize = 0;
                if(items!=null && items.size()>0){
                    itemsize = items.size();
                    List<PenyataAkaun> senaraiAkaunDescending = new ArrayList<PenyataAkaun>(items.size());
                    List<PenyataAkaun> senaraiAkaunAscending = new ArrayList<PenyataAkaun>(items.size());
          
                    for ( StatementResponseLineItem item : items ) {
 
                        PenyataAkaun pa = new PenyataAkaun();
                        //Description
                        pa.setButiran(item.getTHTxDesription().getValue());
                        //Trxn Keluar
                        if(item.getTHTxKeluar().getValue()!=null && !item.getTHTxKeluar().getValue().trim().equals(""))
                            pa.setKeluar(new BigDecimal(item.getTHTxKeluar().getValue()).multiply(new BigDecimal("0.01")));
                        //Trxn Masuk
                        if(item.getTHTxMasuk().getValue()!=null && !item.getTHTxMasuk().getValue().trim().equals(""))
                            pa.setMasuk(new BigDecimal(item.getTHTxMasuk().getValue()).multiply(new BigDecimal("0.01")));
                        //balance
                        if(item.getTHBalance().getValue()!=null && !item.getTHBalance().getValue().trim().equals("")){
                            BigDecimal baki = new BigDecimal(item.getTHBalance().getValue()).multiply(new BigDecimal("0.01"));
                            pa.setBaki(baki);
                        }
//                        //trxn Keluar
//                        if(item.getTHTxKeluar().getValue()!=null && !item.getTHTxKeluar().getValue().trim().equals("")) {
//                            pa.setKeluar(item.getTHTxKeluar().getValue().trim());
//                        }
//                        //Trxn Masuk
//                        if(item.getTHTxMasuk().getValue()!=null && !item.getTHTxMasuk().getValue().trim().equals("")) {
//                            pa.setMasuk(item.getTHTxMasuk().getValue().trim());
//                        }
//                        //balance
//                        if(item.getTHBalance().getValue()!=null && !item.getTHBalance().getValue().trim().equals("")){
//                            pa.setBaki(item.getTHBalance().getValue().trim());
//                        }
                        //TrxnDate
                        pa.setTarikhTransaksi(dateformat.parse(item.getTHTxDate().getValue()));
                        //Seqnumber
                        Integer seqnum = Integer.parseInt(item.getTHSeq().getValue().trim());
                        senaraiAkaunAscending.add(seqnum.intValue()-1, pa); //set as ascending list
                    }

                    int m = 0;
                    for ( int i = itemsize; i>0; i--) {                    
                        PenyataAkaun pa = (PenyataAkaun)senaraiAkaunAscending.get(i-1);
                        senaraiAkaunDescending.add(m, pa);
                        m++;
                    }                
                    deposit.setSenaraiTransaksiAkaun(senaraiAkaunDescending); 
                }
                sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
                getContext().getRequest().getSession().setAttribute("deposit", deposit);               
                return new JSP("deposit/show_account_statement.jsp");
               // return new JSP("deposit/show_account_statement_main.jsp");
            }           
            
        } catch (Exception ex) {
        // TODO handle custom exceptions here
            LOG.error("error {}", ex);
            System.out.println("error = " +  ex);
            responseCode = SYSTEM_ERROR;
        }  
        sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
        addSimpleError("" + responseManager.getResponseMessage(responseCode, STAT_ENQ_MSG_ID));
        //return new JSP("deposit/msg.jsp");
        return new JSP("deposit/show_account_statement_main.jsp");
    }
   
    public Resolution genReportsPenyataAkaun() throws Exception {
              
      Deposit deposit = (Deposit)getContext().getRequest().getSession().getAttribute("deposit");
      
      /**
       * comment to make cetak works in IE8
       */
      //getContext().getRequest().getSession().removeAttribute("deposit");
        
       SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");                           
          
            String month = "";
            List list = new ArrayList(5);
            List penyataList = deposit.getSenaraiTransaksiAkaun();
            if(penyataList != null){
                for (int i = 0; i < penyataList.size(); i++) {
                    Map map1 = new HashMap();
                    PenyataAkaun pa = (PenyataAkaun)penyataList.get(i);  
                    
                    String simpledt = d.format(pa.getTarikhTransaksi());
                    map1.put("p_tarikh", simpledt);
                    map1.put("p_butiran", pa.getButiran()); 
                    if(pa.getKeluar() != null){
                    map1.put("p_keluar", pa.getKeluar());
                    }
                    if(pa.getMasuk() != null){
                    map1.put("p_masuk", pa.getMasuk());
                    }
                    if(pa.getBaki() != null){
                    map1.put("p_jumlah", pa.getBaki());
                    }
                    list.add(map1);                
                 }
            }  
            Map parameter = new HashMap();
            parameter.put("p_list", list);
            parameter.put("p_nama", deposit.getNama());
            parameter.put("p_alamat1", deposit.getAlamat1());
            parameter.put("p_alamat2", deposit.getAlamat2());
            parameter.put("p_alamat3", deposit.getAlamat3());
            parameter.put("p_poskod", deposit.getPoskod());
            parameter.put("p_negeri", deposit.getNegeriDesc());
            
             if (deposit.getBulanPilihan() != null) {
                
                String a = deposit.getBulanPilihan().trim();
                String bulan = a.substring(0,2);
                String thn = a.substring(2);
                System.out.println("Bulan Pilihan : " + a );
                System.out.println("tahun b4 : " + thn);
                System.out.println("Bulan b4 : " + bulan);
                int mn = Integer.parseInt(bulan);
                month = theMonth(mn-1);
                System.out.println("Bulan Pilihan : " + month);
                String mnthYear = month.concat(" ").concat(thn);
                parameter.put("bulanTahun", mnthYear);
            } else {
                parameter.put("bulanTahun", "");
            }
             
           // String simpled = d.format(deposit.getTarikhTransaksi());
            
          //  parameter.put("p_tarikh", simpled);
            parameter.put("p_no_akaun", deposit.getNoAkaun());
            parameter.put("p_no_pengenalan", deposit.getNoKp());
            //add in 14102014
            parameter.put("p_no_kp_penjaga", deposit.getNoKpPenjaga());
            
            String reportpath = conf.getProperty("report.path");            
            parameter.put("SUBREPORT_DIR", reportpath); 
            parameter.put("REPORT_DIR", reportpath);                   
           
            
   //     final byte[] b = reportUtil.generateReportJasper("penyata_akaun.jasper", parameter);
        JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"penyata_akaun.jasper", parameter, new JREmptyDataSource());
        final byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint1);
        InputStream inputStream = new ByteArrayInputStream(bytes);
        getContext().getResponse().setContentType("application/octet-stream" );
        return new StreamingResolution ("application/pdf", inputStream);
       
//        return new StreamingResolution("application/pdf") {
//
//            @Override
//            public void stream(HttpServletResponse response) throws Exception {
////                response.setHeader("Cache-Control", "no-cache");
////                response.setHeader("Pragma", "no-cache");
////                response.setDateHeader("Expires", 0);
////                response.setContentType("application/pdf");
////                response.setHeader("Content-disposition", "inline; filename=test.pdf");
////                ServletOutputStream out = response.getOutputStream();
////                out.write(bytes);
////                out.flush();
////                out.close();
//                InputStream inputStream = new ByteArrayInputStream(bytes);
//                BufferedInputStream bis = new BufferedInputStream(inputStream);
//                ByteArrayOutputStream bous = new ByteArrayOutputStream();
//                
//                int ch;
//                while ((ch = bis.read()) != -1) {
//                    bous.write(ch);
//                }
//                bous.writeTo(response.getOutputStream());
//            }
//        }.setFilename("penyata_akaun");
    }

    //-+-+-+-+-+-+-+-+-+-+-+-+-+-PENYATA KAD-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
    /**
     * Deploy on 22/08/2014
     * @return 
     */
    public Resolution showPenyataKad(){
        if(deposit==null)
            deposit = new Deposit();
        return new JSP("deposit/penyata_kad_form.jsp");
    }    
    
    public Resolution getPenyataKad() {   
        
        AccCheckUtil checking = ableContextListener.newInstance(AccCheckUtil.class);        
        
        deposit.setNoKpDari(deposit.getNoKp());
        deposit.setNoAkaunDari(deposit.getNoAkaun());
        deposit.setBulanPilihan(deposit.getBulanPilihan());
        
        boolean check = checking.checkAcc(deposit, pengguna);
        
        if (!check) {
            addSimpleError("" + responseManager.getResponseMessage("9000", BAL_ENQ_MSG_ID));
            return new JSP("deposit/msg.jsp");
        }
       
        DecimalFormat formatter = new DecimalFormat("#,###.##");
        SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");
        DateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        DateFormat format = new SimpleDateFormat("yyyyMMdd");
        String responseCode = "";
        SejarahTransaksi sejarahTransaksi = new SejarahTransaksi();
        
        //by selected month, get start and end date
        //selected month = 032014 MMyyyy
        
         String selectedMonth = deposit.getBulanPilihan();
         String month = selectedMonth.substring(0, 2);
         String year = selectedMonth.substring(2, 6);
         
         //get start date
         String firstDate = sdf.format(getFirstDayOfMonth(month, year));
         String lastDate = sdf.format(getLastDayOfMonth(month, year));

        try {
            
            com.oas.thit._this.cardstmt.xsd.CardStatementRequest reqCard = new com.oas.thit._this.cardstmt.xsd.CardStatementRequest();
            com.oas.thit._this.cardstmt.xsd.ObjectFactory objFacCard = new com.oas.thit._this.cardstmt.xsd.ObjectFactory();
            com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();

           
            reqCard.setHeader(webUtil.createHeader(STAT_CARD_ENQ_MSG_ID, HEADER_ID_CARD_STATEMENT_ENQUIRY));
            com.oas.thit._this.cardstmt.xsd.CardStatementRequestBody reqBodyCard = new com.oas.thit._this.cardstmt.xsd.CardStatementRequestBody();

            
            reqBodyCard.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(deposit.getNoAkaun()));
            reqBodyCard.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(deposit.getNoKp()));
            reqBodyCard.setTHStmtStartDate(objFacCard.createCardStatementRequestBodyTHStmtStartDate(firstDate));
            reqBodyCard.setTHStmtEndDate(objFacCard.createCardStatementRequestBodyTHStmtEndDate(lastDate));
            
            JAXBElement<CardStatementRequestBody> jCardReqBody = objFacCard.createCardStatementRequestBody(reqBodyCard);  
            reqCard.setBody(jCardReqBody);
            
            com.oas.thit._this.cardstmt.xsd.CardStatementResponse result = port.cardStatement(reqCard);
            Header header = result.getHeader().getValue();
            responseCode = header.getResponseCode().getValue();
     
            sejarahTransaksi.setPengguna(pengguna);
            sejarahTransaksi.setTrhMasuk(new Date());
            sejarahTransaksi.setUrusan(kodUrusanDAO.findById(STAT_CARD_ENQ_MSG_ID));
            sejarahTransaksi.setIdSessi(getContext().getRequest().getSession().getId());
            sejarahTransaksi.setStatus(kodStatusDAO.findById(responseCode));
            sejarahTransaksi.setNilaiDalaman1(header.getTxid().getValue().trim());  
            
            if (responseCode.equals(SUCCESSFUL))    {           
                
                CardStatementResponseBody resp = result.getBody().getValue();
                deposit.setNama(resp.getTHName().getValue());
                deposit.setAlamat1(resp.getTHAddress1().getValue());
                deposit.setAlamat2(resp.getTHAddress2().getValue());
                deposit.setAlamat3(resp.getTHAddress3().getValue());
                deposit.setPoskod(resp.getTHPoskod().getValue());
                deposit.setNoAkaun( resp.getTHAcct().getValue() ); 
                deposit.setNoKp(resp.getTHICNo().getValue());
                deposit.setNegeriDesc(resp.getTHState().getValue().trim());
                deposit.setNoKad(resp.getTHCardNo().getValue().trim());
                
                List<CardStatementResponseLineItem> items  = resp.getLineItems();
                int itemsize = 0;
                if(items!=null && items.size()>0){
                    itemsize = items.size();
                    List<PenyataKad> senaraiAkaunDescending = new ArrayList<PenyataKad>(items.size());
                    List<PenyataKad> senaraiAkaunAscending = new ArrayList<PenyataKad>(items.size());
          
                    for ( CardStatementResponseLineItem item : items ) {
 
                        PenyataKad pa = new PenyataKad();
                        //Tarikh Transaksi
                        pa.setTarikhTransaksi(format.parse(item.getTHTxDate().getValue()));
                        //Tarikh Process
                        pa.setTarikhTerima(format.parse(item.getTHPostingDate().getValue()));
                        //Description
                        pa.setButiran(item.getTHTxDesription().getValue());
//                        //Amaun Debit
//                        if (item.getTHTxMasuk().getValue() != null) {
//                            pa.setAmounKredit(item.getTHTxMasuk().getValue().trim());
//                        }
//                        //Amaun Kredit
//                        if (item.getTHTxKeluar() != null) {
//                            pa.setAmaunDebit(item.getTHTxKeluar().getValue().trim());
//                        }
                        //Amaun Debit
                        if(item.getTHTxMasuk().getValue()!=null && !item.getTHTxMasuk().getValue().trim().equals(""))
                            pa.setAmaunDebit(new BigDecimal(item.getTHTxMasuk().getValue()).multiply(new BigDecimal("0.01")));
                        //Amaun Kredit
                        if(item.getTHTxKeluar().getValue()!=null && !item.getTHTxKeluar().getValue().trim().equals(""))
                            pa.setAmaunKredit(new BigDecimal(item.getTHTxKeluar().getValue()).multiply(new BigDecimal("0.01")));
   
                        Integer seqnum = Integer.parseInt(item.getTHSeq().getValue().trim());
                        senaraiAkaunAscending.add(seqnum.intValue()-1, pa); //set as ascending list
                      
                    }

                    int m = 0;
                    for ( int i = itemsize; i>0; i--) {                    
                        PenyataKad pa = (PenyataKad)senaraiAkaunAscending.get(i-1);
                        senaraiAkaunDescending.add(m, pa);
                        m++;
                    }             
                
                    deposit.setSenaraiTransaksiKad(senaraiAkaunDescending); 
                }
                sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
                getContext().getRequest().getSession().setAttribute("deposit", deposit);               
                return new JSP("deposit/penyata_kad.jsp");
            }           
            
          }catch (Exception ex) {
           
        // TODO handle custom exceptions here
            LOG.error("PAMIE ENSEM {}", ex);
            System.out.println("error = " +  ex);
            responseCode = SYSTEM_ERROR;
        }  
            
           sejarahTransaksiManager.saveSejarahTransaksi(sejarahTransaksi);
           addSimpleError("" + responseManager.getResponseMessage(responseCode, STAT_CARD_ENQ_MSG_ID));
           return new JSP("deposit/msg.jsp");
    }
    
    public Resolution genReportsPenyataKad() throws Exception {
      
        Deposit deposit = (Deposit)getContext().getRequest().getSession().getAttribute("deposit");
        SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy");     
        
        List list = new ArrayList();
        String month = "";
        List penyataKadList = deposit.getSenaraiTransaksiKad();

            if(penyataKadList != null){
                for (int i = 0; i < penyataKadList.size(); i++) {
                    Map mapKad = new HashMap();
                    PenyataKad pKad = (PenyataKad)penyataKadList.get(i);  
                    
                    String tarikhTrans = d.format(pKad.getTarikhTransaksi());
                    mapKad.put("tarikhTrans", tarikhTrans);
                    String tarikhTerima = d.format(pKad.getTarikhTerima());
                    mapKad.put("tarikhTerima", tarikhTerima);
                    mapKad.put("butiran", pKad.getButiran()); 
                    if (pKad.getAmaunDebit() != null) {
//                        Double amtD = Double.parseDouble(pKad.getAmaunDebit());
//                        mapKad.put("amaunDebit", amtD);
                    mapKad.put("amaunDebit", pKad.getAmaunDebit());
                    }
                    if (pKad.getAmaunKredit() != null) {
//                        Double amtK = Double.parseDouble(pKad.getAmaunKredit());
//                        mapKad.put("amaunKredit", amtK);
                    mapKad.put("amaunKredit", pKad.getAmaunKredit());
                    }
                    list.add(mapKad);     
                    
                 }
            }  
    
            Map parameter = new HashMap();
            parameter.put("list", list);
            parameter.put("nama", deposit.getNama());
            parameter.put("alamat1", deposit.getAlamat1());
            parameter.put("alamat2", deposit.getAlamat2());
            parameter.put("alamat3", deposit.getAlamat3());
            parameter.put("poskod", deposit.getPoskod());
            parameter.put("negeri", deposit.getNegeriDesc());
            
//            String simpled = d.format(deposit.getTarikhTransaksi());
//            
//            parameter.put("p_tarikh", simpled);
            parameter.put("noAkaun", deposit.getNoAkaun());
            parameter.put("noKp", deposit.getNoKp());
            parameter.put("noKad", deposit.getNoKad());
            
            if (deposit.getBulanPilihan() != null) {
                
                String a = deposit.getBulanPilihan().trim();
                String bulan = a.substring(0,2);
                String thn = a.substring(2);
                System.out.println("Bulan Pilihan : " + a );
                System.out.println("tahun b4 : " + thn);
                System.out.println("Bulan b4 : " + bulan);
                int mn = Integer.parseInt(bulan);
                month = theMonth(mn-1);
                System.out.println("Bulan Pilihan : " + month);
                String mnthYear = month.concat(" ").concat(thn);
                parameter.put("bulanTahun", mnthYear);
            } else {
                parameter.put("bulanTahun", "");
            }
            
            
            parameter.put("noKad", deposit.getNoKad()); // test
            
                        
            String reportpath = conf.getProperty("report.path");            
            parameter.put("SUBREPORT_DIR", reportpath); 
            parameter.put("REPORT_DIR", reportpath);                   
           
            
        JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"PenyataTHKad.jasper", parameter, new JREmptyDataSource());
        final byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint1);
        InputStream inputStream = new ByteArrayInputStream(bytes);
        getContext().getResponse().setContentType("application/octet-stream" );
        return new StreamingResolution ("application/pdf", inputStream);
          
    }
     
     
    //-+-+-+-+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
    
    public Resolution genReportByIText () {
        
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        
        
        Map<String, Object> map = new HashMap<String, Object>();
        List<PenyataAkaun> listPenyata = new ArrayList<PenyataAkaun>();
        for (int i = 0; i < 5; i++) {
                PenyataAkaun pa = new PenyataAkaun();
//                pa.setBaki(new BigDecimal("100"));
//                pa.setButiran("Pengeluaran");
//                pa.setKeluar(new BigDecimal("100"));
//                pa.setMasuk(BigDecimal.ZERO);
                pa.setTarikhTransaksi(new Date());
                listPenyata.add(pa);
            }
        
        map.put("paramList", listPenyata);         
        
         final byte[] b = reportUtil.generateReportIText( "surat_tawaran_haji.st", map );
         
         return new StreamingResolution("application/pdf") {

            @Override
            public void stream(HttpServletResponse response) throws Exception {
                response.setHeader("Cache-Control", "no-cache");
                response.setHeader("Pragma", "no-cache");
                response.setDateHeader("Expires", 0);
                response.setHeader("Content-disposition", "inline; filename=test.pdf");
                ServletOutputStream out = response.getOutputStream();
                out.write(b, 0, b.length);
                out.flush();
                out.close();

            }
        };
    }
    
    //-+-+-+-+-+-+-+-+-+-+-+-+-+-REPORTS-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//   
    //1)Fund Tranfer
 @DontValidate
 public Resolution fundTransfer() throws Exception {
          
        PindahanSimpanan ps = (PindahanSimpanan)getContext().getRequest().getSession().getAttribute("PindahanSimpanan");
        /**
        * comment to make cetak works in IE8
        */
        //getContext().getRequest().getSession().removeAttribute("PindahanSimpanan");

        SimpleDateFormat d = new SimpleDateFormat("dd/MM/yyyy"); 
        SimpleDateFormat t = new SimpleDateFormat("HH:mm:ss");
      
        HashMap pindahansimpananmap = new HashMap();

        pindahansimpananmap.put("Status",ps.getStatus());
        pindahansimpananmap.put("No. Resit",ps.getNoResit());

        String simpledt = d.format(ps.getTarikhTransaksi());
        String simpletm = t.format(ps.getTarikhTransaksi());

        pindahansimpananmap.put("Transaction Date", simpledt);
        pindahansimpananmap.put("Transaction Time", simpletm);
        pindahansimpananmap.put("Dari Akaun TH",ps.getNoAkaunDari());
        pindahansimpananmap.put("name1",ps.getNama());
        pindahansimpananmap.put("Ke Akaun TH",ps.getNoAkaunPenerima());
        pindahansimpananmap.put("name2",ps.getNamaPenerima());
        pindahansimpananmap.put("Amaun",ps.getAmaun()); 

        String reportpath = conf.getProperty("report.path");
        pindahansimpananmap.put("REPORT_DIR", reportpath);
        
        JasperPrint jasperPrint1 = JasperFillManager.fillReport(reportpath+"PINDAHANSIMPANAN.jasper", pindahansimpananmap, new JREmptyDataSource());
        final byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint1);
        InputStream inputStream = new ByteArrayInputStream(bytes);       
        getContext().getResponse().setContentType("application/octet-stream" );
        return new StreamingResolution ("application/pdf", inputStream);
    
//       return new StreamingResolution("application/pdf") {
//
//            @Override
//            public void stream(HttpServletResponse response) throws Exception {
////                response.setHeader("Cache-Control", "no-cache");
////                response.setHeader("Pragma", "no-cache");
////                response.setDateHeader("Expires", 0);
////                response.setContentType("application/pdf");
////                response.setHeader("Content-disposition", "inline; filename=test.pdf");
////                ServletOutputStream out = response.getOutputStream();
////                out.write(bytes);
////                out.flush();
////                out.close();
//                InputStream inputStream = new ByteArrayInputStream(bytes);
//                BufferedInputStream bis = new BufferedInputStream(inputStream);
//                ByteArrayOutputStream bous = new ByteArrayOutputStream();
//                
//                int ch;
//                while ((ch = bis.read()) != -1) {
//                    bous.write(ch);
//                }
//                bous.writeTo(response.getOutputStream());
//            }
//        }.setFilename("pindahan_simpanan");
 }
    
 
    public Pengguna getPengguna() {
        return pengguna;
    }

    public void setPengguna(Pengguna pengguna) {
        this.pengguna = pengguna;
    }
    
    public ArrayList getPenyataAkaunList() {
        return penyataAkaunList;
    }

    public void setPenyataAkaunList(ArrayList penyataAkaunList) {
        this.penyataAkaunList = penyataAkaunList;
    }

    public List<Akaun> getAccountList() {
        return accountList;
    }

    public void setAccountList(List<Akaun> accountList) {
        this.accountList = accountList;
    }

    public Akaun getAkaun() {
        return akaun;
    }

    public void setAkaun(Akaun akaun) {
        this.akaun = akaun;
    }    

    public Deposit getDeposit() {
        return deposit;
    }

    public void setDeposit(Deposit deposit) {
        this.deposit = deposit;
    }
    
    public void setAccountFavList(List<AkaunFav> acctFavList) {
        this.accFavList = accFavList;
    
    }

    public static String theMonth(int month){
    String[] monthNames = {"JANUARI", "FEBRUARY", "MAC", "APRIL", "MEI", "JUN", "JULAI", "OGOS", "SEPTEMBER", "OKTOBER", "NOVEMBER", "DISEMBER"};
    return monthNames[month];
    }

    public List<AkaunFav> getAccFavList() {
        return accFavList;
    }

    public void setAccFavList(List<AkaunFav> accFavList) {
        this.accFavList = accFavList;
    }
    
    //Validate ACcount
    public String getJenisAkaun (String noAkaun, String noKp) {
        
        Deposit deposit;
        String status = "";
        String responseCode = "";
        
         try { 
                // Call Web Service Operation
                // TODO initialize WS operation arguments here
                com.oas.thit._this.xsd.THISRequest req = new com.oas.thit._this.xsd.THISRequest();
                // TODO process result here                
                com.oas.thit._this.xsd.ObjectFactory objFactory = new com.oas.thit._this.xsd.ObjectFactory();
                req.setHeader(webUtil.createHeader(VAL_ACC_MSG_ID, HEADER_ID_VAL_ACCOUNT));
                THISBaseDataElementBody reqBody = objFactory.createTHISBaseDataElementBody();
                
                reqBody.setTHAcct(objFactory.createTHISBaseDataElementBodyTHAcct(noAkaun));
                reqBody.setTHICNo(objFactory.createTHISBaseDataElementBodyTHICNo(noKp));
                
                JAXBElement<THISBaseDataElementBody> jReqBody =  objFactory.createTHISRequestBody(reqBody);
                req.setBody(jReqBody);
                
                com.oas.thit._this.pin.xsd.AccountValidationResponse result = port.validateAccount(req);
                
                Header header = result.getHeader().getValue();
                responseCode = header.getResponseCode().getValue();
                    //acct sts active,bankrupt,dormant,sulit
                    if (responseCode.equals(SUCCESSFUL)) {
                        deposit = new Deposit();
                        AccountValidationResponseBody resp = result.getBody().getValue(); 
                        if(resp.getTHAcctType()!=null){
                            String jenisAcc = resp.getTHAcctType().getValue().trim();
                            KodAkaun jenisAkaun = kodAkaunDAO.findById(jenisAcc);
                            if (jenisAkaun != null)
                              deposit.setJenisAkaun(jenisAcc); 
                            status = deposit.getJenisAkaun();
                        }
                    }
                
                } catch (Exception ex) {
                    LOG.error("error {}", ex);
                    responseCode = SYSTEM_ERROR;
                    status = "";
                    addSimpleError("" + responseManager.getResponseMessage(responseCode, ADD_ACC_MSG_ID)); 
                    
                }
         
        return status;
    }
}
